package com.ymtms.costaccounting.controller;

import com.ymtms.costaccounting.pojo.FinancialFee;
import com.ymtms.costaccounting.pojo.FinancialFeeDel;
import com.ymtms.costaccounting.service.FinancialFeeService;
import com.ymtms.costaccounting.vo.RequestBean;
import com.ymtms.costaccounting.vo.Result;
import com.ymtms.costaccounting.vo.ResultUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.WebRequest;

import javax.validation.Valid;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @auther: autumn-luo
 * @description:
 * @createTime: 2019-10-30 10:57
 */
@Controller
@CrossOrigin
@Log4j2
public class FinancinalFeeController {

    @Autowired
    FinancialFeeService financialFeeService;
    @InitBinder
    public void initBinder(WebDataBinder binder, WebRequest request) {
        //转换日期 注意这里的转化要和传进来的字符串的格式一直 如2015-9-9 就应该为yyyy-MM-dd
        DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));// CustomDateEditor为自定义日期编辑器
    }
    @RequestMapping("/ffeeAdd")
    @ResponseBody
    public ResultUtil ffeeAdd(@Valid FinancialFee financialFee) {
        log.info("financialFee:"+financialFee);
        financialFeeService.ffeeAdd(financialFee);

        return ResultUtil.success();
    }

    @RequestMapping("/ffeeUpdate")
    @ResponseBody
    public ResultUtil ffeeUpdate(@Valid FinancialFee financialFee) {

        financialFeeService.ffeeUpdate(financialFee);

        return ResultUtil.success();
    }

    /*
     * @createTime 2019-10-30 16:10
     * @author autumn-luo
     * @param: financialFeeDel
     * @return:
     * @description: 财务费用删除
     */
    @RequestMapping("/ffeeDel")
    @ResponseBody
    public ResultUtil ffeeDel(@Valid FinancialFeeDel financialFeeDel) {

        financialFeeService.ffeeDel(financialFeeDel.getFfidDel());

        return ResultUtil.success();
    }

    /*
     * @createTime 2019-10-30 15:54
     * @author autumn-luo
     * @param: requestBean
     * @param: ffeeInfo
     * @return:
     * @description: 财务费用添加
     */
    @RequestMapping("/ffeeAll")
    @ResponseBody
    public ResultUtil ffeeAll(RequestBean requestBean, String ffeeInfo) {
        Result ffeeAll = financialFeeService.ffeeAll(requestBean, ffeeInfo);
        return ResultUtil.success(ffeeAll);
    }

}
